<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>相书保险</title>
    <link rel="stylesheet" href="css/project.css">
    <script src="js/libs/jquery-3.0.0.min.js"></script>
    <script src="js/libs/jquery-weui.min.js"></script>
    <script src="js/libs/vue2.0.js"></script>
    <!-- 引入pdf插件 -->
    <!--<script src="js/libs/parsley.min.js"></script>-->
    <!--<script src="js/libs/pdf.min.js"></script>-->

    <script src="js/project.js"></script>
    <style>
        body{background-color: #f2f3f8;padding-top: 44px;padding-bottom: 50px;}

        /* 底部按钮 */
        .qc-btn-group{
            position: fixed;
            bottom: 0;
            width: 100%;
            background-color: #f2f3f8;
            padding: 0;
            border-radius: 0;
        }
        .qc-btn-group .weui_btn{
            border: none;
            border-radius: 0;
        }
        .qc-btn-group .weui_btn_plain_default{
            background-color: transparent;
            color: #68709a;
            padding: 0 20px;
        }

    </style>
</head>
<body>
<div id="app">
    <div >
        <!-- 头部 -->
        <header class="fixed_top">
            <div class="header_left" onclick="history.go(-1)">
                <i class="iconfont icon-back"></i>
            </div>
            <div class="header_title">保单详情</div>
        </header>

        <div class="weui_cells weui_cells_access">
            <a @click="jumpTo(insurencePDF)" class="weui_cell" download="newfilename">
                <div class="weui_cell_hd weui_cell_primary">电子保单</div>
                <div class="weui_cell_ft"></div>
            </a>
            <div v-if="modifyPDF" class="weui_cell"  @click="jumpTo(modifyPDF)">
                <div class="weui_cell_hd weui_cell_primary">批单(保单修改批复)</div>
                <div class="weui_cell_ft"></div>
            </div>

            <!-- 已过期保单 -->
            <div class="qc-btn-group  u-card" v-if="overDue">
                <a href="index.html" class="weui_btn">再次购买</a>
            </div>

            <!-- 已生效保单 -->
            <div class="qc-btn-group weui_cell" v-else>
                <div class="weui_cell_hd">
                    <a onclick="applyModify()" class="weui_btn weui_btn_plain_default">申请修改</a>
                </div>
                <div class="weui_cell_bd weui_cell_primary">
                    <a onclick="sendToEmail()" class="weui_btn">发送保单到邮箱</a>
                </div>
            </div>
        </div>
    </div>

</div>
<script>

    var orderId = '';
    var vm = new Vue({
        el: '#app',
        data: function () {
            return {
                overDue:false,   // 是否过期
                showPDF: false,
                PDFTitle:'',
                insurencePDF:'',
                modifyPDF:''
            }
        },
        methods: {
            jumpTo (url){
                if(!url){
                    showInfo('正在生成电子保单，请稍后再试');
                    return false
                }
                window.location.href = url;
            }
        },
        created: function () {
            var _this = this;
            orderId = getUrlParam('orderId');
            var url = '/wego168-xsinsurance-wechat/policy/getPolicyPdfById.jsp';
            $.get(url,{orderId:orderId}, function (data) {
                data = JSON.parse(data);
                if(data.errcode === 0){
                    _this.insurencePDF = data.insurencePDF;
                    _this.modifyPDF = data.modifyPDF;
                }else {
                    showInfo(data.errMsg)
                }
            })
        }
    });

    /* 申请修改 */
    function applyModify() {
        window.location.href = 'update.html?orderId='+orderId;
     /*   $.modal({
            title: "温馨提示",
            text: "请拍摄您的身份证照片作为修改人证明",
            buttons: [
                { text: "暂不拍", className: "default", onClick: function(){ console.log(1)} },
                { text: "去拍照", className: "primary", onClick: function(){
                    // TODO:拍照
                    window.location.href = 'update.html';
                } }
            ]
        });*/
    }

    /* 发送保单到邮箱 */
    function sendToEmail() {
        $.prompt({
            title: '填写邮箱',
            empty: false, // 是否允许为空
            onOK: function (input) {
                //点击确认
                var reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
                if(!reg.test(input)){
                    showInfo('邮箱格式错误');
                    return false
                }else {
                    var url = '/wego168-xsinsurance-wechat/policy/sendPolicyEmail.jsp';
                    $.post(url,{ orderId:orderId, email:input}, function (data) {
                        data = JSON.parse(data);
                        if(data.errcode === 0){
                            showInfo('电子保单发送成功！')
                        }else {
                            showInfo(data.errMsg)
                        }
                    })
                }
                console.log(input);
            },
            onCancel: function () {
                //点击取消
            }
        });
    }

</script>

</body>
</html>